package com.hangwei.paperless.fragment.sub;

import android.content.Intent;
import android.graphics.drawable.ColorDrawable;
import android.os.Bundle;
import android.support.annotation.NonNull;
import android.support.v7.widget.GridLayoutManager;
import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.text.TextUtils;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.EditText;
import android.widget.PopupWindow;
import android.widget.RelativeLayout;
import android.widget.TextView;

import com.chad.library.adapter.base.BaseQuickAdapter;
import com.chad.library.adapter.base.listener.OnItemChildClickListener;
import com.hangwei.paperless.BigPicActivity;
import com.hangwei.paperless.EditSubPartCheckActivity;
import com.hangwei.paperless.R;
import com.hangwei.paperless.adapter.Disposition1Adapter;
import com.hangwei.paperless.adapter.DispositionAdapter;
import com.hangwei.paperless.adapter.HorizontalPicAdapter;
import com.hangwei.paperless.model.bean.CardToSeal;
import com.hangwei.paperless.model.bean.Disposition;
import com.hangwei.paperless.model.bean.PartCheckInfo;
import com.hangwei.paperless.model.bean.SubPartCheckSealBean;
import com.hangwei.paperless.presenter.StaticPresenter;
import com.hangwei.paperless.utils.Density;
import com.hangwei.paperless.utils.NFCCallBack;
import com.hangwei.paperless.view.SealHelper;
import com.hangwei.paperless.widget.MyTextWatcher;
import com.twelve.all.base.LoadFragment;
import com.twelve.all.net.CallBack;
import com.twelve.all.utils.ConformDialog;
import com.twelve.all.utils.LoadingDialog;
import com.twelve.all.utils.SPKey;
import com.twelve.all.utils.SPUtil;
import com.twelve.all.utils.ToastUtil;
import com.twelve.all.utils.Tools;

import java.util.ArrayList;
import java.util.List;

/**
 * Created by 张龙臣 on 2020/12/10.
 */

public class SubEditPartCheckFragment extends LoadFragment {

    //    private MainBottomPopupWindow mMainBottomPopupWindow;
    private RelativeLayout mFlUserSeal;
    private PartCheckInfo mPartCheckInfo;
    private List<Disposition> mDispositionList;
    private RelativeLayout mFlTName;
    private ArrayList<String> mPicList;
    private View mInflate;
    private EditSubPartCheckActivity mActivity;
    private RecyclerView mRecyclerViewDis;
    private Disposition1Adapter mAdapter;
    private String mSavedActual;
    private EditText mEtGrind;
    private EditText mEtDIM;

    @Override
    protected View onRealCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
        Bundle arguments = getArguments();
        if (arguments != null) {
            mPartCheckInfo = (PartCheckInfo) arguments.getSerializable("item");
            mPicList = arguments.getStringArrayList("picList");
            mActivity = (EditSubPartCheckActivity) getActivity();
        }
        mInflate = inflater.inflate(R.layout.page_sub_edit_part_check, container, false);
        mInflate.findViewById(R.id.back).setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                finish();
            }
        });

        if (mPartCheckInfo != null) {
            mPartCheckInfo.isComplete = !TextUtils.isEmpty(mPartCheckInfo.technicianId) || !TextUtils.isEmpty(mPartCheckInfo.grindTechId);
        }

        RecyclerView recyclerView = mInflate.findViewById(R.id.recyclerView);
        LinearLayoutManager layout = new LinearLayoutManager(getActivity());
        layout.setOrientation(LinearLayoutManager.HORIZONTAL);
        recyclerView.setLayoutManager(layout);
        recyclerView.setAdapter(new HorizontalPicAdapter(mPicList));
        recyclerView.addOnItemTouchListener(new OnItemChildClickListener() {
            @Override
            public void onSimpleItemChildClick(BaseQuickAdapter adapter, View view, int position) {
                if (view.getId() == R.id.sdv) {
                    Intent intent = new Intent(getActivity(), BigPicActivity.class);
                    intent.putExtra("list", mPicList);
                    intent.putExtra("position", position);
                    startActivity(intent);
                }
            }
        });
        Helper helper = new Helper();
        helper.setText(R.id.tvSeq, Tools.checkedString(mPartCheckInfo.seq))
                .setText(R.id.tvSeq1, Tools.checkedString(mPartCheckInfo.location))
                .setText(R.id.tvPartCheck, Tools.checkedString(mPartCheckInfo.checkItem))
                .setText(R.id.tvDesignMin, TextUtils.isEmpty(Tools.checkedString(mPartCheckInfo.dlMin)) ? "--" : Tools.checkedString(mPartCheckInfo.dlMin))
                .setText(R.id.tvDesignMax, TextUtils.isEmpty(Tools.checkedString(mPartCheckInfo.dlMax)) ? "--" : Tools.checkedString(mPartCheckInfo.dlMax))
                .setText(R.id.tvReworkMin, TextUtils.isEmpty(Tools.checkedString(mPartCheckInfo.rlMin)) ? "--" : Tools.checkedString(mPartCheckInfo.rlMin))
                .setText(R.id.tvReworkMax, TextUtils.isEmpty(Tools.checkedString(mPartCheckInfo.rlMax)) ? "--" : Tools.checkedString(mPartCheckInfo.rlMax))
                .setText(R.id.etActual, Tools.checkedString(mPartCheckInfo.actual))
                .setText(R.id.etRemark, Tools.checkedString(mPartCheckInfo.remark))
//                .setText(R.id.tvDisposition, Tools.checkedString(mPartCheckInfo.disposition))
                .setText(R.id.etDIM, Tools.checkedString(mPartCheckInfo.dimAfterRework))
                .setText(R.id.etGrind, Tools.checkedString(mPartCheckInfo.dimAfterGrind));
//                .setText(R.id.flTName, Tools.checkedString(item.seq))
        mFlTName = mInflate.findViewById(R.id.flTName);
        mFlUserSeal = mInflate.findViewById(R.id.flUserSeal);

        setSealStatus(mPartCheckInfo.billId);

//        RelativeLayout rlDisposition = mInflate.findViewById(R.id.rlDisposition);
        EditText etActual = mInflate.findViewById(R.id.etActual);
        mEtGrind = mInflate.findViewById(R.id.etGrind);
        mEtDIM = mInflate.findViewById(R.id.etDIM);
        mRecyclerViewDis = mInflate.findViewById(R.id.recyclerViewDis);
        mRecyclerViewDis.setLayoutManager(new GridLayoutManager(mActivity, 5));
        mAdapter = new Disposition1Adapter(null);
        mRecyclerViewDis.setAdapter(mAdapter);
        TextView tvSave = mInflate.findViewById(R.id.tvSave);
        etActual.addTextChangedListener(new MyTextWatcher() {
            @Override
            public void onTextChanged(CharSequence s, int start, int before, int count) {
                if (!TextUtils.isEmpty(mSavedActual)) {
                    if (mSavedActual.equals(s.toString().trim())) {
                        etActual.setBackgroundResource(R.drawable.et_shape_green);
                    } else etActual.setBackgroundResource(R.drawable.et_enable_selector);
                }
            }
        });
        tvSave.setOnClickListener(v -> {
            ArrayList<String> list = getDisList();
            if (list.size() == 0) {
                ToastUtil.showCenterToast("请选择处理方案！");
                return;
            }
            String trim = etActual.getText().toString().trim();
            if (TextUtils.isEmpty(trim)) {
                new ConformDialog(mActivity, "未输入实际尺寸，是否继续操作？") {
                    @Override
                    protected void onConfirm() {
                        saveDis(etActual, list, trim);
                    }
                };
            } else {
                boolean range = checkRange(trim, mPartCheckInfo.rlMin, mPartCheckInfo.rlMax);
                if (range) {
                    saveDis(etActual, list, trim);
                } else {
                    new ConformDialog(mActivity, "超出修理极限范围，是否继续保存？") {
                        @Override
                        protected void onConfirm() {
                            saveDis(etActual, list, trim);
                        }
                    };
                }
            }
        });
        if (TextUtils.isEmpty(mPartCheckInfo.grindTechId)) {
            mEtGrind.setEnabled(true);
        } else {
            mEtGrind.setEnabled(false);
            mEtGrind.setHint("");
        }
        if (TextUtils.isEmpty(mPartCheckInfo.technicianId)) {
            mEtDIM.setEnabled(true);
        } else {
            mEtDIM.setEnabled(false);
            mEtDIM.setHint("");
        }
        if (mPartCheckInfo.isComplete) {
            mEtGrind.setEnabled(false);
            mEtGrind.setHint("");
            mEtDIM.setEnabled(false);
            mEtDIM.setHint("");
        }

//        if (mPartCheckInfo.isComplete) {
//            etActual.setEnabled(false);
////            etGrind.setEnabled(false);
//            mEtDIM.setEnabled(false);
//        } else {
//            etActual.setEnabled(true);
////            etGrind.setEnabled(true);
//            mEtDIM.setEnabled(true);
//        }
//        etActual.addTextChangedListener(new MyTextWatcher() {
//            @Override
//            public void onTextChanged(CharSequence s, int start, int before, int count) {
//                String trim = s.toString().trim();
//                if (!TextUtils.isEmpty(trim)) {
//                    double parseDouble = Double.parseDouble(trim);
//                    if (mPartCheckInfo.rlMin != null && mPartCheckInfo.rlMin > parseDouble) {
//                        etActual.setText(String.valueOf(mPartCheckInfo.rlMin));
//                    }
//                    if (mPartCheckInfo.rlMax != null && mPartCheckInfo.rlMax < parseDouble) {
//                        etActual.setText(String.valueOf(mPartCheckInfo.rlMax));
//                    }
//                }
//            }
//        });
//        etDIM.addTextChangedListener(new MyTextWatcher() {
//            @Override
//            public void onTextChanged(CharSequence s, int start, int before, int count) {
//                String trim = s.toString().trim();
//                if (!TextUtils.isEmpty(trim)) {
//                    double parseDouble = Double.parseDouble(trim);
//                    if (mPartCheckInfo.rlMin != null && mPartCheckInfo.rlMin > parseDouble) {
//                        etDIM.setText(String.valueOf(mPartCheckInfo.rlMin));
//                    }
//                    if (mPartCheckInfo.rlMax != null && mPartCheckInfo.rlMax < parseDouble) {
//                        etDIM.setText(String.valueOf(mPartCheckInfo.rlMax));
//                    }
//                }
//            }
//        });
//        etGrind.addTextChangedListener(new MyTextWatcher() {
//            @Override
//            public void onTextChanged(CharSequence s, int start, int before, int count) {
//                String trim = s.toString().trim();
//                if (!TextUtils.isEmpty(trim)) {
//                    double parseDouble = Double.parseDouble(trim);
//                    if (mPartCheckInfo.dlMin != null && mPartCheckInfo.dlMin > parseDouble) {
//                        etGrind.setText(String.valueOf(mPartCheckInfo.dlMin));
//                    }
//                    if (mPartCheckInfo.dlMax != null && mPartCheckInfo.dlMax < parseDouble) {
//                        etGrind.setText(String.valueOf(mPartCheckInfo.dlMax));
//                    }
//                }
//            }
//        });
        mEtGrind.setEnabled(TextUtils.isEmpty(mPartCheckInfo.grindTechId));
//        final TextView tvDisposition = mInflate.findViewById(R.id.tvDisposition);
        etActual.addTextChangedListener(new MyTextWatcher() {
            @Override
            public void onTextChanged(CharSequence s, int start, int before, int count) {
                mPartCheckInfo.actual = s.toString().trim();
            }
        });
        mEtGrind.addTextChangedListener(new MyTextWatcher() {
            @Override
            public void onTextChanged(CharSequence s, int start, int before, int count) {
                mPartCheckInfo.dimAfterGrind = s.toString().trim();
            }
        });
        mEtDIM.addTextChangedListener(new MyTextWatcher() {
            @Override
            public void onTextChanged(CharSequence s, int start, int before, int count) {
                mPartCheckInfo.dimAfterRework = s.toString().trim();
            }
        });
//        rlDisposition.setOnClickListener(new NotFastClickListener() {
//            @Override
//            protected void isNotFastClick(View v) {
//                if (mPartCheckInfo.isComplete) return;
//                if (mDispositionList == null || mDispositionList.size() == 0) {
//                    assert getActivity() != null;
//                    final LoadingDialog loadingDialog = new LoadingDialog(getActivity());
//                    loadingDialog.show();
//                    StaticPresenter.getDispositionList(SPUtil.getString(SPKey.Account.USER_ID), new CallBack<List<Disposition>>() {
//                        @Override
//                        public void onCompleted(List<Disposition> dispositions) {
//                            loadingDialog.dismiss();
//                            if (dispositions != null && dispositions.size() > 0)
//                                for (Disposition bean : dispositions) {
//                                    if (bean.id != null && bean.id.equals(mPartCheckInfo.dispositionId)) {
//                                        bean.isChecked = true;
//                                        break;
//                                    }
//                                }
//                            mDispositionList = dispositions;
//                            showDisPop(tvDisposition);
//                        }
//
//                        @Override
//                        public void onError() {
//                            loadingDialog.dismiss();
//                        }
//                    });
//                } else showDisPop(tvDisposition);
//            }
//        });
        loadDis();
        return mInflate;
    }

    @NonNull
    private ArrayList<String> getDisList() {
        ArrayList<String> list = new ArrayList<>();
        for (Disposition dis : mAdapter.getData()) {
            if (dis.isChecked)
                list.add(dis.name);
        }
        return list;
    }

    private void saveDis(EditText etActual, ArrayList<String> list, String trim) {
        StringBuilder builder = new StringBuilder();
        for (int i = 0; i < list.size(); i++) {
            builder.append(list.get(i));
            if (i != list.size() - 1)
                builder.append(",");
        }
        LoadingDialog loadingDialog = new LoadingDialog(mActivity);
        loadingDialog.show();
        String userId = SPUtil.getString(SPKey.Account.USER_ID);
        StaticPresenter.saveICRDisposition(userId, mPartCheckInfo.id, trim, builder.toString(), new CallBack<Object>() {
            @Override
            public void onCompleted(Object o) {
                loadingDialog.dismiss();
                ToastUtil.showCenterToast("保存成功！");
                mSavedActual = trim;
                etActual.setBackgroundResource(R.drawable.et_shape_green);
            }

            @Override
            public void onError() {
                loadingDialog.dismiss();
            }
        });
    }

    private void loadDis() {
        StaticPresenter.getDispositionList(SPUtil.getString(SPKey.Account.USER_ID), new CallBack<List<Disposition>>() {
            @Override
            public void onCompleted(List<Disposition> dispositions) {
                if (dispositions != null && dispositions.size() > 0 && mPartCheckInfo != null && mPartCheckInfo.disposition != null && mPartCheckInfo.disposition.size() > 0) {
                    for (String str : mPartCheckInfo.disposition)
                        for (Disposition dis : dispositions) {
                            if (str != null && str.equals(dis.name))
                                dis.isChecked = true;
                        }
                }
                mAdapter.setNewData(dispositions);
            }

            @Override
            public void onError() {
            }
        });
    }

    private boolean checkRange(String trim, String min, String max) {
        double num;
        if (TextUtils.isEmpty(trim))
            num = 0;
        else
            num = Double.parseDouble(trim);
        double minNum = 0;
        if (!TextUtils.isEmpty(min)) {
            minNum = Double.parseDouble(min);
        }
        double maxNum = 0;
        if (!TextUtils.isEmpty(max))
            maxNum = Double.parseDouble(max);
        if (minNum != 0 && num < minNum)
            return false;
        if (maxNum != 0 && num > maxNum)
            return false;
        return true;
    }

    private void setSealStatus(String billId) {
//        if (TextUtils.isEmpty(mPartCheckInfo.reworkRoleId)) {
//            mFlTName.removeAllViews();
//        } else {
//        }
        reloadUser(billId);
//        LinearLayout llT = findViewById(R.id.llT);
//        if (TextUtils.isEmpty(mPartCheckInfo.grindRoleId)) {
//            mFlUserSeal.removeAllViews();
//        } else {
//        }
        reloadGrind(billId);
    }

    private void reloadGrind(String billId) {
        SealHelper sealHelper1 = new SealHelper(getActivity()) {//磨削
            @Override
            protected void onSeal() {
                String trim = mEtGrind.getText().toString().trim();
                if (TextUtils.isEmpty(trim)) {
                    new ConformDialog(mActivity, "磨削后尺寸未输入，确认操作吗？") {
                        @Override
                        protected void onConfirm() {
                            seal(2, billId);
//                            boolean range = checkRange(trim, mPartCheckInfo.dlMin, mPartCheckInfo.dlMax);
//                            if (range)
//                                seal(2, billId);
//                            else {
//                                ToastUtil.showCenterToast("磨削后尺寸不能超出设计范围!");
//                            }
                        }
                    };
                } else {
                    boolean range = checkRange(trim, mPartCheckInfo.dlMin, mPartCheckInfo.dlMax);
                    if (range)
                        seal(2, billId);
                    else {
                        ToastUtil.showCenterToast("磨削后尺寸不能超出设计范围!");
                    }
                }

            }
        };
        sealHelper1.bindData(new SealHelper.SealBean(true, mPartCheckInfo.grindTechStampId, mPartCheckInfo.grindTechId, mPartCheckInfo.grindTechStampTypeCode, mPartCheckInfo.grindTechStampCode, mPartCheckInfo.grindTechDate, mPartCheckInfo.grindTech, true));
        mFlUserSeal.removeAllViews();
        mFlUserSeal.addView(sealHelper1.getItemView());
    }

    private void reloadUser(String billId) {
        SealHelper sealHelper = new SealHelper(getActivity()) {//工作者
            @Override
            protected void onSeal() {
                String trim = mEtDIM.getText().toString().trim();
                if (TextUtils.isEmpty(trim)) {
                    new ConformDialog(mActivity, "修理后尺寸未输入，确认操作吗？") {
                        @Override
                        protected void onConfirm() {
                            seal(1, billId);
//                            boolean range = checkRange(trim, mPartCheckInfo.rlMin, mPartCheckInfo.rlMax);
//                            if (range)
//                                seal(1, billId);
//                            else new ConformDialog(mActivity, "超出修理极限范围，是否继续提交？") {
//                                @Override
//                                protected void onConfirm() {
//                                    seal(1, billId);
//                                }
//                            };
                        }
                    };
                } else {
                    boolean range = checkRange(trim, mPartCheckInfo.rlMin, mPartCheckInfo.rlMax);
                    if (range)
                        seal(1, billId);
                    else new ConformDialog(mActivity, "超出修理极限范围，是否继续提交？") {
                        @Override
                        protected void onConfirm() {
                            seal(1, billId);
                        }
                    };
                }
            }
        };
        sealHelper.bindData(new SealHelper.SealBean(true, mPartCheckInfo.technicianStampId, mPartCheckInfo.technicianId, mPartCheckInfo.technicianStampTypeCode, mPartCheckInfo.technicianStampCode, mPartCheckInfo.technicianDate, mPartCheckInfo.technician, !mPartCheckInfo.isComplete));
        mFlTName.removeAllViews();
        mFlTName.addView(sealHelper.getItemView());
    }

    private void showDisPop(final TextView tvDisposition) {
        final PopupWindow window = new PopupWindow(getActivity());
        View inflate = LayoutInflater.from(getActivity()).inflate(R.layout.pop_value_choose, null);
        RecyclerView recyclerView = inflate.findViewById(R.id.recyclerView);
        recyclerView.setLayoutManager(new LinearLayoutManager(getActivity()));
        recyclerView.setAdapter(new DispositionAdapter(mDispositionList) {
            @Override
            protected void onAdapterItemClick(int position) {
                Disposition disposition = mDispositionList.get(position);
                tvDisposition.setText(Tools.checkedString(disposition.name));
                tvDisposition.setTextColor(getResources().getColor(R.color.black));
                mPartCheckInfo.dispositionId = disposition.id;
                mPartCheckInfo.grindRoleId = disposition.grindRoleId;
                mPartCheckInfo.reworkRoleId = disposition.reworkRoleId;
                mPartCheckInfo.grindTech = disposition.grindTech;
                setSealStatus(mPartCheckInfo.billId);
                window.dismiss();
            }
        });
        window.setContentView(inflate);
        window.setWidth(ViewGroup.LayoutParams.WRAP_CONTENT);
        window.setHeight(ViewGroup.LayoutParams.WRAP_CONTENT);
        window.setBackgroundDrawable(new ColorDrawable());
        window.setOutsideTouchable(true);
        window.setFocusable(true);
        assert getActivity() != null;
        window.showAsDropDown(tvDisposition, Density.dip2px(getActivity(), 28f), Density.dip2px(getActivity(), 3f));
    }

    private void seal(final int stampRole, String billId) {
        if (mPartCheckInfo == null) return;
        mActivity.sealByCard(billId, new NFCCallBack() {
            @Override
            public void onCallBack(List<CardToSeal.StampBean> stampIds, String userId) {
                if (stampIds == null || stampIds.size() == 0) {
                    ToastUtil.showCenterToast("无印章！");
                } else {
                    final LoadingDialog loadingDialog = new LoadingDialog(getActivity());
                    loadingDialog.show();
                    String userId0 = SPUtil.getString(SPKey.Account.USER_ID);
                    StaticPresenter.stampInspectionRecordSheet(userId0, mPartCheckInfo.id, stampRole, mPartCheckInfo.actual, mPartCheckInfo.dispositionId, mPartCheckInfo.dimAfterRework, mPartCheckInfo.dimAfterGrind, userId, stampIds.get(0).stampId, new CallBack<SubPartCheckSealBean>() {
                        @Override
                        public void onCompleted(SubPartCheckSealBean o) {
                            loadingDialog.dismiss();

//                            mMainBottomPopupWindow.dismiss();
                            mPartCheckInfo.technicianStampId = o.technicianStampId;
                            mPartCheckInfo.technicianId = o.technicianId;
                            mPartCheckInfo.technicianStampTypeCode = o.technicianStampTypeCode;
                            mPartCheckInfo.technicianStampCode = o.technicianStampCode;
                            mPartCheckInfo.technicianDate = o.technicianDate;
                            mPartCheckInfo.technician = o.technician;
                            mPartCheckInfo.grindTechStampId = o.grindTechStampId;
                            mPartCheckInfo.grindTechId = o.grindTechId;
                            mPartCheckInfo.grindTechStampTypeCode = o.grindTechStampTypeCode;
                            mPartCheckInfo.grindTechStampCode = o.grindTechStampCode;
                            mPartCheckInfo.grindTechDate = o.grindTechDate;
                            mPartCheckInfo.grindTech = o.grindTech;
                            if (stampRole == 1) {
                                reloadUser(billId);
                                if (TextUtils.isEmpty(mPartCheckInfo.technicianId)) {
                                    mEtDIM.setEnabled(true);
                                } else {
                                    mEtDIM.setEnabled(false);
                                    mEtDIM.setHint("");
                                }
//                                mFlTName.setBackgroundColor(getResources().getColor(R.color.white));
//                                SealHelper sealHelper = new SealHelper(getActivity()) {
//                                    @Override
//                                    protected void onSeal() {
//
////                                        String trim = mEtDIM.getText().toString().trim();
////                                        if (TextUtils.isEmpty(trim)) {
////                                            ToastUtil.showCenterToast("请输入修理后尺寸！");
////                                            return;
////                                        }
////                                        boolean range = checkRange(trim, mPartCheckInfo.rlMin, mPartCheckInfo.rlMax);
////                                        if (range)
////                                            seal(1, billId);
////                                        else new ConformDialog(mActivity, "超出修理极限范围，是否继续提交？") {
////                                            @Override
////                                            protected void onConfirm() {
////                                                seal(1, billId);
////                                            }
////                                        };
//                                    }
//                                };
//                                SealHelper.SealBean sealBean = new SealHelper.SealBean(true, o.technicianStampId, o.technicianId, o.technicianStampTypeCode, o.technicianStampCode, o.technicianDate, o.technician, true);
//                                sealHelper.bindData(sealBean);
//                                mFlTName.removeAllViews();
//                                mFlTName.addView(sealHelper.getItemView());
                            } else if (stampRole == 2) {
                                mPartCheckInfo.isComplete = true;
                                if (TextUtils.isEmpty(mPartCheckInfo.grindTechId)) {
                                    mEtGrind.setEnabled(true);
                                } else {
                                    mEtGrind.setEnabled(false);
                                    mEtGrind.setHint("");
                                }
                                mEtGrind.setEnabled(false);
                                mEtGrind.setHint("");
                                mEtDIM.setEnabled(false);
                                mEtDIM.setHint("");
                                reloadUser(billId);
                                reloadGrind(billId);
//                                SealHelper sealHelper1 = new SealHelper(getActivity()) {
//                                    @Override
//                                    protected void onSeal() {
//                                        String trim = mEtGrind.getText().toString().trim();
//                                        if (TextUtils.isEmpty(trim)) {
//                                            ToastUtil.showCenterToast("请输入磨削后尺寸！");
//                                            return;
//                                        }
//                                        boolean range = checkRange(trim, mPartCheckInfo.dlMin, mPartCheckInfo.dlMax);
//                                        if (range)
//                                            seal(2, billId);
//                                        else {
//                                            ToastUtil.showCenterToast("磨削后尺寸不能超出设计范围!");
//                                        }
//                                    }
//                                };
//                                SealHelper.SealBean sealBean = new SealHelper.SealBean(true, o.grindTechStampId, o.grindTechId, o.grindTechStampTypeCode, o.grindTechStampCode, o.grindTechDate, o.grindTech, true);
//                                sealHelper1.bindData(sealBean);
//                                mFlUserSeal.removeAllViews();
//                                mFlUserSeal.addView(sealHelper1.getItemView());
                            }
                        }

                        @Override
                        public void onError() {
                            loadingDialog.dismiss();
                        }
                    });
                }
            }
        });
//        if (App.stamps != null && App.stamps.size() > 0) {
//            //有印章
//            View inflate = LayoutInflater.from(getActivity()).inflate(R.layout.pop_seal, null);
//            mMainBottomPopupWindow = new MainBottomPopupWindow(getActivity(), inflate, BottomPopType.Seal);
//            mMainBottomPopupWindow.setNeedAlpha(false);
//            mMainBottomPopupWindow.setOnSealListener(new MainBottomPopupWindow.OnSealListener() {
//                @Override
//                public void onSeal(String stampId) {
//                    final LoadingDialog loadingDialog = new LoadingDialog(getActivity());
//                    loadingDialog.show();
//                    String userId = SPUtil.getString(SPKey.Account.USER_ID);
//                    StaticPresenter.stampInspectionRecordSheet(userId, mPartCheckInfo.id, stampRole, mPartCheckInfo.actual, mPartCheckInfo.dispositionId, mPartCheckInfo.dimAfterRework, mPartCheckInfo.dimAfterGrind, userId, stampId, new CallBack<SubPartCheckSealBean>() {
//                        @Override
//                        public void onCompleted(SubPartCheckSealBean o) {
//                            loadingDialog.dismiss();
//                            mPartCheckInfo.isComplete = true;
//                            mMainBottomPopupWindow.dismiss();
//                            mPartCheckInfo.technicianStampId = o.technicianStampId;
//                            mPartCheckInfo.technicianId = o.technicianId;
//                            mPartCheckInfo.technicianStampTypeCode = o.technicianStampTypeCode;
//                            mPartCheckInfo.technicianDate = o.technicianDate;
//                            mPartCheckInfo.grindTechStampId = o.grindTechStampId;
//                            mPartCheckInfo.grindTechId = o.grindTechId;
//                            mPartCheckInfo.grindTechStampTypeCode = o.grindTechStampTypeCode;
//                            mPartCheckInfo.grindTechStampCode = o.grindTechStampCode;
//                            mPartCheckInfo.grindTechDate = o.grindTechDate;
//                            if (stampRole == 1) {
//                                mFlTName.setBackgroundColor(getResources().getColor(R.color.white));
//                                SealHelper sealHelper = new SealHelper(getActivity()) {
//                                    @Override
//                                    protected void onSeal() {
//                                        seal(1, billId);
//                                    }
//                                };
//                                SealHelper.SealBean sealBean = new SealHelper.SealBean(true, o.technicianStampId, o.technicianId, o.technicianStampTypeCode, o.technicianStampCode, o.technicianDate, true);
//                                sealHelper.bindData(sealBean);
//                                mFlTName.removeAllViews();
//                                mFlTName.addView(sealHelper.getItemView());
//                            } else if (stampRole == 2) {
//                                SealHelper sealHelper1 = new SealHelper(getActivity()) {
//                                    @Override
//                                    protected void onSeal() {
//                                        seal(2, billId);
//                                    }
//                                };
//                                SealHelper.SealBean sealBean = new SealHelper.SealBean(true, o.grindTechStampId, o.grindTechId, o.grindTechStampTypeCode, o.grindTechStampCode, o.grindTechDate, true);
//                                sealHelper1.bindData(sealBean);
//                                mFlUserSeal.removeAllViews();
//                                mFlUserSeal.addView(sealHelper1.getItemView());
//                            }
//                            mMainBottomPopupWindow.dismiss();
//                        }
//
//                        @Override
//                        public void onError() {
//                            loadingDialog.dismiss();
//                        }
//                    });
//                }
//            });
//            mMainBottomPopupWindow.showAtLocation(mFlUserSeal, Gravity.BOTTOM, 0, 0);
//        } else {
//            ToastUtil.showCenterToast("无印章");
//        }
    }

    private class Helper {
        public Helper setText(int id, String text) {
            View viewById = mInflate.findViewById(id);
            ((TextView) viewById).setText(text);
            return this;
        }
    }
}
